package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.logistic.domain.NetworkUndertakeCentreOverview;
import com.ruoyi.logistic.domain.NetworkUndertakeCentreStorehouseCollect;
import com.ruoyi.logistic.domain.NetworkUndertakeCentreStorehouseDetail;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreOverviewVo;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreStorehouseCollectVo;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreStorehouseDetailVo;
import com.ruoyi.logistic.mapper.NetworkUndertakeCentreOverviewMapper;
import com.ruoyi.logistic.mapper.NetworkUndertakeCentreStorehouseCollectMapper;
import com.ruoyi.logistic.mapper.NetworkUndertakeCentreStorehouseDetailMapper;
import com.ruoyi.logistic.service.NetworkUndertakeCentreStorehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NetworkUndertakeCentreStorehouseServiceImpl implements NetworkUndertakeCentreStorehouseService {
    @Autowired
    private NetworkUndertakeCentreStorehouseDetailMapper networkUndertakeCentreStorehouseDetailMapper;
    @Autowired
    private NetworkUndertakeCentreStorehouseCollectMapper networkUndertakeCentreStorehouseCollectMapper;
    @Autowired
    private NetworkUndertakeCentreOverviewMapper networkUndertakeCentreOverviewMapper;
    @Override
    public List<NetworkUndertakeCentreStorehouseDetail> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return networkUndertakeCentreStorehouseDetailMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkUndertakeCentreStorehouseDetail networkUndertakeCentreStorehouseDetail) {
        return networkUndertakeCentreStorehouseDetailMapper.insert(networkUndertakeCentreStorehouseDetail);
    }

    @Override
    public Boolean update(NetworkUndertakeCentreStorehouseDetail networkUndertakeCentreStorehouseDetail) {
        return networkUndertakeCentreStorehouseDetailMapper.update(networkUndertakeCentreStorehouseDetail);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkUndertakeCentreStorehouseDetailMapper.deleteById(id);
    }

    @Override
    public List<NetworkUndertakeCentreStorehouseDetail> search(NetworkUndertakeCentreStorehouseDetailVo networkUndertakeCentreStorehouseDetailVo) {
        PageHelper.startPage(networkUndertakeCentreStorehouseDetailVo.getPageDate());
        return networkUndertakeCentreStorehouseDetailMapper.search(networkUndertakeCentreStorehouseDetailVo);
    }

    @Override
    public List<NetworkUndertakeCentreStorehouseCollect> storehouseCollect(NetworkUndertakeCentreStorehouseCollectVo networkUndertakeCentreStorehouseCollectVo) {
        PageHelper.startPage(networkUndertakeCentreStorehouseCollectVo.getPageDate());
        List<NetworkUndertakeCentreStorehouseCollect> storehouseCollects = networkUndertakeCentreStorehouseCollectMapper.storehouseCollect(networkUndertakeCentreStorehouseCollectVo);
        for (NetworkUndertakeCentreStorehouseCollect storehouseCollect :storehouseCollects){
            storehouseCollect.setSettleDate(networkUndertakeCentreStorehouseCollectVo.getMonth());
        }
        return storehouseCollects;
    }

    @Override
    public List<NetworkUndertakeCentreOverview> overview(NetworkUndertakeCentreOverviewVo networkUndertakeCentreOverviewVo) {
        PageHelper.startPage(networkUndertakeCentreOverviewVo.getPageDate());
        List<NetworkUndertakeCentreOverview> overviews = networkUndertakeCentreOverviewMapper.overview(networkUndertakeCentreOverviewVo);
        for (NetworkUndertakeCentreOverview overview : overviews){
            if (networkUndertakeCentreOverviewVo.getCollectDimensionality().equals(1)){
                overview.setMonth(networkUndertakeCentreOverviewVo.getStartTime() + "至" + networkUndertakeCentreOverviewVo.getEndTime());
            }else {
                overview.setMonth(networkUndertakeCentreOverviewVo.getMonth());
            }
        }
        return overviews;
    }
}
